/* Copyright 2010 by Matt Van Der Westhuizen */

package org.chaoticengine.ast.model;

import org.chaoticengine.ast.pattern.Model;

/**
 * Model of the game world map, which can contain towns, airships and different
 * terrain types.
 *
 * @author Matt Van Der Westhuizen <mattpwest@gmail.com>
 */
public class World extends Model implements HasTurn {
    /** Number of days since the simulation started. */
    protected float days = 0.0f;

    /** Number of hours since midnight. */
    protected float hours = 0.0f;

    /** Length of a day in hours. */
    protected float dayLength = 24.0f;

    /** Length of a turn in hours. */
    protected float turnLength = 1.0f;

    /** Map of the world. */
    protected WorldMap map = null;

    protected boolean paused = true;

    public World() {
        super();
    }

    public float getDay() {
        return days;
    }

    public float getHours() {
        return(hours);
    }
    
    public WorldMap getMap() {
        return map;
    }

    public void setMap(WorldMap map) {
        this.map = map;
        refreshObservers();
    }

    public float getTurnLength() {
        return turnLength;
    }

    /**
     * Set the turn length in days (or fractions of a day).
     * @param turnLength Number of days to complete one turn.
     */
    public void setTurnLength(float turnLength) {
        this.turnLength = turnLength;
    }

    public float getDayLength() {
        return dayLength;
    }

    public void setDayLength(float dayLength) {
        this.dayLength = dayLength;
    }

    public void takeTurn(float hours) {
        this.hours += hours;
        if (this.hours >= dayLength) {
            float d = this.hours / dayLength;
            this.days += d;
            this.hours -= dayLength * d;
        }

        map.takeTurn(hours);

        refreshObservers();
    }

    public boolean getPaused() {
        return(paused);
    }

    public void togglePaused() {
        if (paused) {
            paused = false;
        } else {
            paused = true;
        }
    }
}
